package com.xuecheng.content.api;

import com.xuecheng.base.exception.ValidationGroups;
import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.content.model.dto.AddCourseDto;
import com.xuecheng.content.model.dto.CourseBaseInfoDto;
import com.xuecheng.content.model.dto.EditCourseDto;
import com.xuecheng.content.model.dto.QueryCourseParamsDto;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.service.CourseBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author luhao
 * @ClassName CourseBaseInfoController.java
 * @Description 课程信息编辑接口
 * @createTime 2023/5/11
 */
@RestController
@Api(tags = "课程基础信息api")
public class CourseBaseInfoController {
    @Autowired
    private CourseBaseService courseBaseService;
    @ApiOperation(value = "分页查询课程信息")
    @PostMapping("/course/list")
    public PageResult<CourseBase> findByPage(@Validated PageParams pageParams,
                                             @ApiParam(value = "条件查询参数")@RequestBody(required = false) QueryCourseParamsDto queryCourseParamsDto) {
        PageResult<CourseBase> pageResult = courseBaseService.queryByPage(pageParams, queryCourseParamsDto);
        return pageResult;
    }
    @ApiOperation("添加课程信息")
    @PostMapping("/course")
    public CourseBaseInfoDto saveCourseInfo(@RequestBody @Validated(ValidationGroups.Insert.class) AddCourseDto addCourseDto){
        // 机构id，单点登录获取
        Long companyId = 1232141425L;
        CourseBaseInfoDto courseBaseInfoDto = courseBaseService.addCourseInfo(companyId, addCourseDto);
        return courseBaseInfoDto;
    }
    @ApiOperation("根据Id查询课程信息")
    @GetMapping("/course/{courseId}")
    public CourseBaseInfoDto findCourseById(@ApiParam(value = "课程Id",required = true)@PathVariable Long courseId){
        CourseBaseInfoDto courseBaseInfoDto = courseBaseService.queryCourseById(courseId);
        return courseBaseInfoDto;
    }

    @ApiOperation("修改课程信息")
    @PutMapping("/course")
    public CourseBaseInfoDto editCourseInfo(@RequestBody @Validated(ValidationGroups.Update.class) EditCourseDto editCourseDto) {
        // 获取课程机构id
        Long companyId = 1232141425L;
        CourseBaseInfoDto courseBaseInfoDto = courseBaseService.amendCourseInfo(companyId, editCourseDto);
        return courseBaseInfoDto;
    }

    @ApiOperation("删除课程信息")
    @DeleteMapping ("/course/{courseId}")
    public void dropCourseInfo(@ApiParam(value = "课程Id",required = true) @PathVariable Long courseId) {
        // 获取课程机构id
        Long companyId = 1232141425L;
        courseBaseService.removeCourseInfo(companyId, courseId);
    }
}
